<?php

/**
 * oRs
 *
 * @version 3.0
 * @copyright 2009 Ron Planken
 * @class: attributes
 * @description: Handles the actions for attributes
 */

class attributes {

	private $_system;
	
	function __construct($system) {
		$this->_system = $system;
	}

	function get($attribute_id = 0){

  	if ($attribute_id == 0) {
			$query ='SELECT  id
                			,name
                			,short_name
                			,description
                			,type
                			,picture_link
						FROM attribute
					GROUP BY id;
							';
		} else {
			
			$attribute_id = $this->_system->_db->secure_int($attribute_id);
			
			$query = "SELECT id
                			,name
                			,short_name
                			,description
                			,type
                			,picture_link
						FROM attribute
					   WHERE id = $attribute_id;
							";
		}

		$attributes = $this->_system->_db->SelectMultiQuery($query);

		return $attributes;

	}

	function save($id, $name, $short_name, $description, $type, $picture_link) {

    $id = $this->_system->_db->secure_int($id);
    $name = $this->_system->_db->secure_string($name);
    $short_name = $this->_system->_db->secure_string($short_name);
    $description = $this->_system->_db->secure_string($description);
    $type = $this->_system->_db->secure_int($type);
    $picture_link = $this->_system->_db->secure_string($picture_link);

		if ($id == 0) {
			$query ="INSERT INTO attribute
						   ( id
                			,name
                			,short_name
                			,description
                			,type
                			,picture_link
						   )
					VALUES ( $id
                			,$name
                			,$short_name
                			,$description
                			,$type
                			,$picture_link
						   )
							";
			$status = $this->_system->_db->InsertQuery($query);

		} else {
			$query ="UPDATE  attribute
						SET  name = $name
                			,short_name = $short_name
                			,description = $description
                			,type = $type
                			,picture_link = $picture_link
					  WHERE id = $id
							";
			$status = $this->_system->_db->UpdateQuery($query);
		}

		return $status;

	}

	function remove($attribute_id = 0) {

		$attribute_id = $this->_system->_db->secure_int($attribute_id);

		$query ="DELETE FROM attribute
				  	   WHERE id = $attribute_id;
							";
		$status = $this->_system->_db->UpdateQuery($query);

		return $status;
	}

}
?>